package cn.kaiux.bigdata.homework.week05_06

import java.net.URI

/**
 * @author kaiux@foxmail.com
 * @date 2022/6/11 13:09
 */
trait DistCPResult extends Serializable {
  def getMessage: String
}

trait CopyResult extends DistCPResult

case class FileCopyResult(source: URI, destination: URI, len: Long, copyAction: FileCopyActionResult) extends CopyResult {
  def getMessage: String = s"Source: [$source], Destination: [$destination], Type: [FileCopy: $len bytes], Result: [${copyAction.message}]"
}

case class DirectoryCopyResult(source: URI, destination: URI, copyAction: DirectoryCreateActionResult) extends CopyResult {
  def getMessage: String = s"Source: [$source], Destination: [$destination], Type: [DirectoryCreate], Result: [${copyAction.message}]"
}

sealed trait CopyActionResult extends Serializable {
  def message: String = this.getClass.getSimpleName.stripSuffix("$")
}

sealed trait DirectoryCreateActionResult extends CopyActionResult

sealed trait FileCopyActionResult extends CopyActionResult

object CopyActionResult {

  object SkippedAlreadyExists extends FileCopyActionResult with DirectoryCreateActionResult

  object Created extends DirectoryCreateActionResult

  object Copied extends FileCopyActionResult

  object OverwrittenOrUpdated extends FileCopyActionResult

  case class Failed(e: Throwable) extends FileCopyActionResult with DirectoryCreateActionResult {
    override def message: String = s"${super.message}: ${e.getMessage}"
  }

}